package com.qf.hotel.controller.foodtype;

import com.qf.hotel.pojo.FoodType;
import com.qf.hotel.service.FoodTypeService;
import com.qf.hotel.service.impl.FoodTypeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @author: GsheN丶
 * @date: 2021/6/25 1:23
 * @description:用ID查找的控制层
 */
//@WebServlet("/foodtype/findById")
public class FoodTypeFindByIdController extends HttpServlet {

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //1字符编码设置
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");


        try {
            //2收参
            String typeId = request.getParameter("typeId");

            //3调用业务方法查询
            FoodTypeService foodTypeService = new FoodTypeServiceImpl();
            FoodType foodType = foodTypeService.findById(Integer.parseInt(typeId));



            //4.把foodType对象存储在域对象中
            request.setAttribute("foodType",foodType);


            //5.转发到显示数据的页面,请求修改页面
            request.getRequestDispatcher("/backend/detail/foodtype/foodtype-update.jsp").forward(request,response);
        } catch (SQLException e) {
            e.printStackTrace();
        }




    }
}
